
		

-- D:\GOA\reslibrary\templete\res\modal\modalmgr.xsl 58
gr_module("gm_xinbanchunzhongyun")


mcgfwarehousemgr = inherit(GmSql.list,GmBase.CallBack):name("mcgfwarehousemgr")



mcgfwarehousemgr.init = function (self,pagecount)

	local top = self
	
	
	GmSql.list.init(self,gInfo["path"]..'/'..g_local_db_name,'czy_warehouse')
	GmBase.CallBack.init(self)
	
	self.baseurl = ''

	self.idPair = {}
	self.idPair['prev'] = '0'
	self.idPair['next'] = '0'
	
	self.pageCount = pagecount or 10
	self.totalPage = 0
	
	self:reset_maxminid('czy_warehouse','id')
	
	
	self.action = {}
	self.op  = {}
	
	
	
	-----------------------------
	self.action['cgfwarehousedetail'] = {} 	
	-------
	self.op['cgfwarehousedetail'] = function(postparam,ui)
	
		local net = GmBase.czynet.get_instance()		
		local newpostparam = {}
		local tbname,callbackey,newpostparam = net:cgfwarehousedetail()
		for a,b in pairs(top.action['cgfwarehousedetail']) do
			if postparam[a] ~= nil then
				newpostparam[a] = postparam[a]
			end
		end
		net:add_callback(callbackey,ui)	
		local tb,callbackey = net:cgfwarehousedetail(newpostparam)
		
	end	
		
  self.action['cgfwarehousedetail']['id'] = { ['title'] = '编号' , ['t'] = 'n' , ['min'] = 'NaN' , ['max'] = '11' }	
  self.action['cgfwarehousedetail']['name'] = { ['title'] = '名称' , ['t'] = 's' , ['min'] = 'NaN' , ['max'] = '64' }	
  self.action['cgfwarehousedetail']['note'] = { ['title'] = 'note' , ['t'] = 's' , ['min'] = 'NaN' , ['max'] = '32' }	
  self.action['cgfwarehousedetail']['ctype'] = { ['title'] = 'order涓烘垚鍝佷粨浣?,wh涓烘潗鏂欎粨浣?' , ['t'] = 's' , ['min'] = 'NaN' , ['max'] = '32' }	
  self.action['cgfwarehousedetail']['barcode'] = { ['title'] = '鏉＄爜' , ['t'] = 's' , ['min'] = 'NaN' , ['max'] = '20' }
  self.action['cgfwarehousedetail']['list_source'] = { ['title'] = '' ,['t'] = 's' , ['max'] = 50 }
	
	-----------------------------
	self.action['cgfwarehouseitem'] = {} 	
	-------
	self.op['cgfwarehouseitem'] = function(postparam,ui)
	
		local net = GmBase.czynet.get_instance()		
		local newpostparam = {}
		local tbname,callbackey,newpostparam = net:cgfwarehouseitem()
		for a,b in pairs(top.action['cgfwarehouseitem']) do
			if postparam[a] ~= nil then
				newpostparam[a] = postparam[a]
			end
		end
		net:add_callback(callbackey,ui)	
		local tb,callbackey = net:cgfwarehouseitem(newpostparam)
		
	end	
		
  self.action['cgfwarehouseitem']['id'] = { ['title'] = '编号' , ['t'] = 'n' , ['min'] = 'NaN' , ['max'] = '11' }	
  self.action['cgfwarehouseitem']['name'] = { ['title'] = '名称' , ['t'] = 's' , ['min'] = 'NaN' , ['max'] = '64' }	
  self.action['cgfwarehouseitem']['note'] = { ['title'] = 'note' , ['t'] = 's' , ['min'] = 'NaN' , ['max'] = '32' }	
  self.action['cgfwarehouseitem']['ctype'] = { ['title'] = 'order涓烘垚鍝佷粨浣?,wh涓烘潗鏂欎粨浣?' , ['t'] = 's' , ['min'] = 'NaN' , ['max'] = '32' }	
  self.action['cgfwarehouseitem']['barcode'] = { ['title'] = '鏉＄爜' , ['t'] = 's' , ['min'] = 'NaN' , ['max'] = '20' }
  self.action['cgfwarehouseitem']['list_source'] = { ['title'] = '' ,['t'] = 's' , ['max'] = 50 }
	
	-----------------------------
	self.action['cgfwarehousepost'] = {} 	
	-------
	self.op['cgfwarehousepost'] = function(postparam,ui)
	
		local net = GmBase.czynet.get_instance()		
		local newpostparam = {}
		local tbname,callbackey,newpostparam = net:cgfwarehousepost()
		for a,b in pairs(top.action['cgfwarehousepost']) do
			if postparam[a] ~= nil then
				newpostparam[a] = postparam[a]
			end
		end
		net:add_callback(callbackey,ui)	
		local tb,callbackey = net:cgfwarehousepost(newpostparam)
		
	end	
		
  self.action['cgfwarehousepost']['id'] = { ['title'] = '编号' , ['t'] = 'n' , ['min'] = 'NaN' , ['max'] = '11' }	
  self.action['cgfwarehousepost']['name'] = { ['title'] = '名称' , ['t'] = 's' , ['min'] = 'NaN' , ['max'] = '64' }	
  self.action['cgfwarehousepost']['note'] = { ['title'] = 'note' , ['t'] = 's' , ['min'] = 'NaN' , ['max'] = '32' }	
  self.action['cgfwarehousepost']['ctype'] = { ['title'] = 'order涓烘垚鍝佷粨浣?,wh涓烘潗鏂欎粨浣?' , ['t'] = 's' , ['min'] = 'NaN' , ['max'] = '32' }	
  self.action['cgfwarehousepost']['barcode'] = { ['title'] = '鏉＄爜' , ['t'] = 's' , ['min'] = 'NaN' , ['max'] = '20' }
  self.action['cgfwarehousepost']['list_source'] = { ['title'] = '' ,['t'] = 's' , ['max'] = 50 }
	
	-----------------------------
	self.action['cgfwarehousemodify'] = {} 	
	-------
	self.op['cgfwarehousemodify'] = function(postparam,ui)
	
		local net = GmBase.czynet.get_instance()		
		local newpostparam = {}
		local tbname,callbackey,newpostparam = net:cgfwarehousemodify()
		for a,b in pairs(top.action['cgfwarehousemodify']) do
			if postparam[a] ~= nil then
				newpostparam[a] = postparam[a]
			end
		end
		net:add_callback(callbackey,ui)	
		local tb,callbackey = net:cgfwarehousemodify(newpostparam)
		
	end	
		
  self.action['cgfwarehousemodify']['id'] = { ['title'] = '编号' , ['t'] = 'n' , ['min'] = 'NaN' , ['max'] = '11' }	
  self.action['cgfwarehousemodify']['name'] = { ['title'] = '名称' , ['t'] = 's' , ['min'] = 'NaN' , ['max'] = '64' }	
  self.action['cgfwarehousemodify']['note'] = { ['title'] = 'note' , ['t'] = 's' , ['min'] = 'NaN' , ['max'] = '32' }	
  self.action['cgfwarehousemodify']['ctype'] = { ['title'] = 'order涓烘垚鍝佷粨浣?,wh涓烘潗鏂欎粨浣?' , ['t'] = 's' , ['min'] = 'NaN' , ['max'] = '32' }	
  self.action['cgfwarehousemodify']['barcode'] = { ['title'] = '鏉＄爜' , ['t'] = 's' , ['min'] = 'NaN' , ['max'] = '20' }
  self.action['cgfwarehousemodify']['list_source'] = { ['title'] = '' ,['t'] = 's' , ['max'] = 50 }
	
	-----------------------------
	self.action['cgfwarehouselist'] = {} 	
	-------
	self.op['cgfwarehouselist'] = function(postparam,ui)
	
		local net = GmBase.czynet.get_instance()		
		local newpostparam = {}
		local tbname,callbackey,newpostparam = net:cgfwarehouselist()
		for a,b in pairs(top.action['cgfwarehouselist']) do
			if postparam[a] ~= nil then
				newpostparam[a] = postparam[a]
			end
		end
		net:add_callback(callbackey,ui)	
		local tb,callbackey = net:cgfwarehouselist(newpostparam)
		
	end	
		
  self.action['cgfwarehouselist']['id'] = { ['title'] = '编号' , ['t'] = 'n' , ['min'] = 'NaN' , ['max'] = '11' }	
  self.action['cgfwarehouselist']['name'] = { ['title'] = '名称' , ['t'] = 's' , ['min'] = 'NaN' , ['max'] = '64' }	
  self.action['cgfwarehouselist']['note'] = { ['title'] = 'note' , ['t'] = 's' , ['min'] = 'NaN' , ['max'] = '32' }	
  self.action['cgfwarehouselist']['ctype'] = { ['title'] = 'order涓烘垚鍝佷粨浣?,wh涓烘潗鏂欎粨浣?' , ['t'] = 's' , ['min'] = 'NaN' , ['max'] = '32' }	
  self.action['cgfwarehouselist']['barcode'] = { ['title'] = '鏉＄爜' , ['t'] = 's' , ['min'] = 'NaN' , ['max'] = '20' }
  self.action['cgfwarehouselist']['list_source'] = { ['title'] = '' ,['t'] = 's' , ['max'] = 50 }
	
  
 
  	
  
	self.session = {}
	
end   





mcgfwarehousemgr.check_fields_validate = function(self,key,postparam)
	local checkfunc = {}
	checkfunc['t'] = function(fm,value)
		return true
	end
	checkfunc['min'] = function(fm,value)
		if string.len(value) < tonumber(fm) then
			return false
		end
		return true
	end
	checkfunc['max'] = function(fm,value)
		if string.len(value) > tonumber(fm) then
			return false
		end
		return true
	end
	local format = self.action[key]
	for fkey,fvalue in pairs(postparam) do
		if format[fkey] ~= nil then
			for fmkey,fmvalue in pairs(format[fkey]) do
				if checkfunc[fmkey] ~= nil then
					if checkfunc[fmkey](fmvalue,fvalue) == false then
						return false,tostring(format[fkey]['title']).." "..tostring(fmkey).." "..tostring(fmvalue).." error"
					end
				end
			end
		end
	end
	return true,""
end 


 
mcgfwarehousemgr.get_session = function(self,key)
	if key == nil then
		key = 'default'
	end
	return self.session[key]
end

mcgfwarehousemgr.has_session = function(self,key)
	if key == nil then
		key = 'default'
	end
	return self.session[key] ~= nil
end
 
 
mcgfwarehousemgr.add_session = function(self,key,ses)
	self.session[key] = ses
end


mcgfwarehousemgr.add_ui = function(self,key,ui)
	self.uis[key] = ui
end




-- todo
mcgfwarehousemgr.run = function(self,key,ui)
	if self.action[key] ~= nil and self.op[key] ~= nil then
		local tb = {}
		for k,v in pairs(self.action[key]) do
			if ui[k] ~= nil and type(ui[k]) == 'table' and ui[k].get_text then
				tb[k] = ui[k]:get_text()
			else
				print('run error',key,k)
			end
		end
		local success,msg = self:check_fields_validate(key,tb)
		if success then
			self.op[key](tb,ui)
		else
			ui.hostWindow:showMsg(msg)
		end		
	else
		print('run error self.action',key)
	end
end


------------------------------------------------------------------------------------


mcgfwarehousemgr.get_net_page = function(self,netmethon,attrs)
	local top = self	
	local discuz = GmBase.net.get_instance()
	local methon = netmethon
	if methon ~= nil and discuz[methon] then
		print('mcgfwarehousemgr.get_net_page ',methon)
		local tbname,callbackey,tb = discuz[netmethon](discuz)
		for k,v in pairs(attrs) do
			tb[k] = attrs[k]
		end
		discuz[netmethon](discuz,tb)
	else
		print('mcgfwarehousemgr.get_net_page error ',methon)
	end		
end




mcgfwarehousemgr.get_prev_page = function(self,ui,callback)
	if ui.page ~= nil and type(ui.page) == 'number' then
		local uiattrs = ui:GetAttrs()
		local attrs = {}
		for a,b in pairs(self.action['cgfwarehouselist']) do
			if type(uiattrs[a]) ~= nil then
				attrs[a] = uiattrs[a]
			end
		end
		attrs.page = ui.page - 1		

		if attrs.page < 1 then
			attrs.page = 1
		end

		self:get_net_page(ui.netmethon,attrs)
	end
end


mcgfwarehousemgr.get_next_page = function(self,ui,callback)
	if ui.page ~= nil and type(ui.page) == 'number' then
		local uiattrs = ui:GetAttrs()
		local attrs = {}
		for a,b in pairs(self.action['cgfwarehouselist']) do
			if type(uiattrs[a]) ~= nil then
				attrs[a] = uiattrs[a]
			end
		end
		attrs.page = ui.page + 1
		self:get_net_page(ui.netmethon,attrs)
	end
end

------------------------------------------------------------------------------------



mcgfwarehousemgr.init_table = function(self)
	--[[
	local tablefield = {}
	
	--number
	tablefield['id'] = { ["i"] = 11, }
    
	--string
	tablefield['name'] = { ["v"] = 64, }
    
	--string
	tablefield['note'] = { ["v"] = 32, }
    
	--string
	tablefield['ctype'] = { ["v"] = 32, }
    
	--string
	tablefield['barcode'] = { ["v"] = 20, }
    
	self:create_table( self.tablename, tablefield)
	]]
	self:initTableStruct()
end


	